<%
  unless local_assigns.key?(:servers)
    raise 'required params `servers` for this template!'
  end
  unless local_assigns[:without_actions]
    without_actions = false
  end
%>
<table class="table table-bordered table-condensed	">
  <thead>
    <tr>
      <th rowspan="2">ID</th>
      <th rowspan="2">Addr</th>
      <th rowspan="2">Protocol</th>
      <th rowspan="2">MaxQPS</th>
      <th colspan="4" class="text-center">HeathCheck</th>
      <th colspan="5" class="text-center">CircuitBreaker</th>
      <th rowspan="2" class="text-center">操作</th>
    </tr>
    <tr>
      <th>Path</th>
      <th>Body</th>
      <th>CheckInterval(s)</th>
      <th>Timeout(s)</th>
      <% '以下为熔断配置' %>
      <th>CloseTimeout(s)</th>
      <th>HalfTrafficRate(%)</th>
      <th>RateCheckPeriod(s)</th>
      <th>FailureRateToClose(%)</th>
      <th>SucceedRateToOpen(%)</th>
    </tr>
  </thead>
  <tbody>
    <% @servers.each do |server| %>
      <tr>
        <td><%= link_to server.id, server_path(server.id), class: 'btn btn-info btn-xs' %></td>
        <td><%= server.addr %></td>
        <td><%= server.protocol_name %></td>
        <td><%= server.max_qps %></td>

        <% hc = server.heath_check %>
        <td><%= hc.try(:path) %></td>
        <td><%= hc.try(:body) %></td>
        <td><%= hc.try(:check_interval_in_second) %></td>
        <td><%= hc.try(:timeout_in_second) %></td>
        <% cb = server.circuit_breaker %>
        <td><%= cb.try(:close_timeout_in_second) %></td>
        <td><%= cb.try(:half_traffic_rate) %></td>
        <td><%= cb.try(:rate_check_period_in_second) %></td>
        <td><%= cb.try(:failure_rate_to_close) %></td>
        <td><%= cb.try(:succeed_rate_to_open) %></td>

        <td>
          <% if !without_actions %>
            <%= link_to '编辑', edit_server_path(server.id), class: 'btn btn-warning btn-xs' %>
            <%= link_to '删除', server_path(server.id), method: :delete, class: 'btn btn-danger btn-xs', data: {confirm: "你确认删除吗？"} %>
          <% end %>
          <% if local_assigns.key?(:cluster) %>
            <%= link_to '解绑', unbind_server_path(id: server.id, cluster_id: cluster.id), method: :delete, class: 'btn btn-danger btn-xs', data: {confirm: "你确认解绑吗？"} %>
          <% end %>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>
